package com.fund.product.controller;

import com.fund.common.pojo.Result;
import com.fund.api.entity.AvailableShare;
import com.fund.product.service.AvailableShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/availableShare")
public class AvailableShareController {

    @Autowired
    AvailableShareService availableShareService;

    /**
     * 根据客户id查询可用份额
     * @param clientId
     * @return
     */
    @GetMapping("/{clientId}")
    public Result<List<AvailableShare>> getAvailableShare(@PathVariable Long clientId, @RequestParam Long fundId) {
        return Result.success(availableShareService.
                lambdaQuery()
                .eq(AvailableShare::getClientId,clientId)
                .eq(AvailableShare::getFundId,fundId)
                .list());
    }

    @PutMapping
    public Result<Boolean> modifyAvailableShares(@RequestBody List<AvailableShare> availableShares) {
        return Result.success(availableShareService.updateBatchById(availableShares));
    }
}
